package com.my.javaweb;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/***
 * response对象：
 * 使用：
 *      设置响应头：setHeader(String key,String value);在响应头添加响应ang信息，会覆盖同键
 *                 addHeader(String key,String value);。。。。。。。。。。，不会覆盖同键
 *      设置响应编码格式：resp.setContentType("text/html;charset=utf-8");
 *      设置响应状态：sendError（int num,String msg);
 *      设置相应实体：resp.getWriter().write(String str);响应具体数据给浏览器
 *
 *
 *
 * **/
@WebServlet(name = "ResponseDemo" ,urlPatterns = "/resp")
public class ResponseDemo extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
            ///获取请求信息request
            ///处理请求

            ///响应处理结果
                //设置响应头
                    resp.setHeader("mouse","two fly birds.");
                    resp.setHeader("mouse","three fly birds.");
                    resp.addHeader("key","thinkpad");
                    resp.addHeader("key","dasd");
                //设置响应编码格式
                    //resp.setHeader("content-type","text/html;charset=utf-8");
                    resp.setContentType("text/html;charset=utf-8");//一样的
                //设置响应状态码
//                    resp.sendError(405,"message");
                //设置响应实体（如果sendError了就别给实体了
                    resp.getWriter().write("试试中文 ------- this is response.");
    }
}
